Skip to content

fix(opencode): stop materializing MISTRAL_API_KEY into the server env (vibe-direct must bill the Vibe plan) - #6460

Merged
dezren39 merged 1 commit into
mainfrom
fix/vibe-direct-keyring-credential
Nov 6, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/vibe-direct-keyring-credential

Conversation

@dezren39

@dezren39 dezren39 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Root cause

Mistral meters per key, not by call metadata. vibe-direct resolves its credential exactly like the vibe binary \u2014 env MISTRAL_API_KEY first, then ~/.vibe/.env, then the OS keyring (ai.mistral.vibe). The home-manager ExecStartPre materializer exported the Bitwarden mistral.api-key value \u2014 the account API key (sha256 fp 144cdb68\u2026, the same value as the enrolled mistral integration credential) \u2014 into the server unit env, so every vibe-direct request spent the API key and billed the $15 API budget. The keyring sign-in key (fp b782943c\u2026) is a different key and is the one that bills the Vibe plan.

Proven empirically 2026-11-06: the real vibe CLI succeeds on the keyring key while the API budget is exhausted; the same CLI forced onto the server env key returns the exact production error 402 billing_api_budget_exhausted. Attribution: on 2026-11-05, while vibe-direct carried the deepseek-flash-plan load, 8,693 vibe-direct attempts went to Mistral, 8,660 of them inside the 16%->100% burn window (22:45Z wall) \u2014 yes, our own mis-keyed traffic burned the API pool.

Change

  • home/common/default.nix: the materializer no longer writes MISTRAL_API_KEY (DEEPSEEK_API_KEY unchanged); the comment block now records the verified per-key metering behavior. Script renamed opencode-env-key-materialize.
  • .opencode/opencode.jsonc: comments that stated the wrong theory (same-credential legs; call_source as metering key; env key as vibe-direct's credential) corrected.

The mistral provider is unaffected: its enrolled credential is its source (verified live with the env var absent: the leg returns the API-budget 402, not an auth error).

Runtime state / follow-up after this lands + a switch

A runtime bridge is ALREADY live (2026-11-06): user drop-in ~/.config/systemd/user/opencode.service.d/10-vibe-keyring-fix.conf swaps ExecStartPre for a scrub script that deletes only the MISTRAL_API_KEY= line from the materialized env file; verified end-to-end (vibe-direct succeeds, mistral-plan route serves via the vibe leg, plan budget is the one in play). After the next nixos-rebuild switch activates this PR, remove the drop-in and ~/.local/bin/mistral-env-scrub.sh \u2014 left in place they would freeze DEEPSEEK_API_KEY rotation, since the scrub replaces the materializer wholesale.

Refs: developing-today-forks/opencode#1653


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Mistral meters per KEY, not by call metadata. vibe-direct resolves
its credential exactly like the vibe binary (env first), so the
ExecStartPre materializer exporting the Bitwarden mistral.api-key
value (the account API key) silently rerouted all vibe-direct
traffic onto the $15 API budget: it burned the pool 16% -> 100% on
2026-11-05 and then walled the mistral-plan route with 402
billing_api_budget_exhausted.

With MISTRAL_API_KEY absent from the server env, vibe-direct falls
through to the keyring ai.mistral.vibe sign-in key and bills the
Vibe plan, as designed (opencode#1653). The mistral provider is
unaffected: its enrolled credential (integration mistral) is its
source, verified live 2026-11-06.

DEEPSEEK_API_KEY materialization is unchanged. Config comments
that stated the wrong metering theory are corrected.

Refs: developing-today-forks/opencode#1653
@dezren39
dezren39 requested a review from a team as a code owner November 6, 2026 07:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T07:32:31.719640Z 688decc PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 01c97fe into main Nov 6, 2026
@dezren39
dezren39 deleted the fix/vibe-direct-keyring-credential branch November 6, 2026 07:31
@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant